window.onload = function () {
    $('.loading').hide();
    $(".side-pub-thread").remove();
    interest_list();
    //发帖标题字数控制
    $(".thread-title").keyup(function (thisLength, thisValue) {
        thisDom = $(this);
        threadTitleInput();
    });
    $("body").on('paste cut', '.thread-title', function (thisLength, thisValue) {
        thisDom = $(this);
        threadTitleInput();
        setTimeout(function () {
            thisDom.blur();
        }, 50);
        setTimeout(function () {
            thisDom.focus();
        }, 100);
    });
    $(".thread-title").blur(function (thisLength, thisValue) {
        thisDom = $(this);
        threadTitleInput();
    });
    //===================缩略图区域显示/隐藏=====================//
    thumbShow();
};

//保存按钮
$(document).on('click', '#save-thread-btn', function () {
    info_get();
    if (!title_info) {
        layer.msg('未输入标题!')
    } else if (title_info.length < 6 || title_info.length > 30) {
        layer.msg('标题字数长度出错!')
    } else if (!motorcycle_info) {
        layer.msg('未选择类别!')
    } else if (!content_info) {
        layer.msg('未填入任何内容!')
    } else if (!content_cover) {
        layer.msg('您还未设置封面,是否继续', {
            time: 0, //不自动关闭
            btn: ['是', '否'],
            yes: function (index) {
                layer.close(index);
                $.post(url_link + "articles/drafts", {
                    user_id: user_id,
                    type: article_type,
                    title: title_info,
                    mototype_id: motorcycle_info,
                    content: content_info
                }, function (data) {
                    var obj = JSON.parse(data);
                    if (obj.code == 0) {
                        layer.msg("保存成功,正在为您跳转页面...");
                        setTimeout(function () {
                            window.location.href = "../center/drafts.html";
                        }, 1000)
                    }

                })
            }
        });
    } else {
        $.post(url_link + "articles/drafts", {
            user_id: user_id,
            type: article_type,
            title: title_info,
            mototype_id: motorcycle_info,
            content: content_info,
            cover: content_cover
        }, function (data) {
            var obj = JSON.parse(data);
            if (obj.code == 0) {
                layer.msg("保存成功,正在为您跳转页面...");
                setTimeout(function () {
                    window.location.href = "../center/drafts.html";
                }, 1000)
            }

        })
    }
});


//发表按钮
$(document).on('click', '#pub-thread-btn', function () {
    info_get();
    if (!title_info) {
        layer.msg('未输入标题!')
    } else if (title_info.length < 6 || title_info.length > 30) {
        layer.msg('标题字数长度出错!')
    } else if (!motorcycle_info) {
        layer.msg('未选择类别!')
    } else if (!content_info) {
        layer.msg('未填入任何内容!')
    } else if (!content_cover) {
        layer.msg('您还未设置封面,是否继续', {
            time: 0, //不自动关闭
            btn: ['是', '否'],
            yes: function (index) {
                layer.close(index);
                $('.loading').show();
                setTimeout(function(){
                    $.post(url_link + "articles", {
                        user_id: user_id,
                        type: article_type,
                        title: title_info,
                        mototype_id: motorcycle_info,
                        content: content_info
                    }, function (data) {
                        var obj = JSON.parse(data);
                        if (obj.code == 0) {
                            $('.loading').hide();
                            layer.msg("发表成功,正在为您跳转页面...");
                            setTimeout(function () {
                                window.location.href = "show.html?article_id=" + obj.data.article_id;
                            }, 1000)
                        }
                    })
                },3000)

            }
        });
    } else {
        $('.loading').show();
        setTimeout(function () {
            $.post(url_link + "articles", {
                user_id: user_id,
                type: article_type,
                title: title_info,
                mototype_id: motorcycle_info,
                content: content_info,
                cover: content_cover
            }, function (data) {
                var obj = JSON.parse(data);
                if (obj.code == 0) {
                    $('.loading').hide();
                    layer.msg("发表成功,正在为您跳转页面...");
                    setTimeout(function () {
                        window.location.href = "show.html?article_id=" + obj.data.article_id;
                    }, 1000)
                }
            })
        }, 3000)

    }
});






